# @Time : 2021/5/30 11:08
# @Author : Li Kunlun
# @Description : numpy的广播进行测试
import numpy as np

x = np.arange(4)
xx = x.reshape(4, 1)
# [0 1 2 3]

# [[0]
#  [1]
#  [2]
#  [3]]
print(x)
print(xx)

y = np.ones(5)
print("-----------------------")
# [1. 1. 1. 1. 1.]
print(y)

print("-----------------------")
# (4,1)+（5，）后（5，）中每一个数据和(4,1)相加后并向axis=1方向扩展
# [[1. 1. 1. 1. 1.]
#  [2. 2. 2. 2. 2.]
#  [3. 3. 3. 3. 3.]
#  [4. 4. 4. 4. 4.]]
print(xx + y)

y2 = np.array([1, 1, 1, 1, 2])
print("-----------------------")
# [[1 1 1 1 2]
#  [2 2 2 2 3]
#  [3 3 3 3 4]
#  [4 4 4 4 5]]
print(xx + y2)

print("-----------------------")
z = np.ones((3, 4))
# （3,4）+(4,)后(4,)中每一个数据和(3,4)相加后并向axis=0方向扩展
# [[1. 2. 3. 4.]
#  [1. 2. 3. 4.]
#  [1. 2. 3. 4.]]
print(x + z)
